home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_400 / 424_02 / ED-157 / buffer_app.c < prev    next >
C/C++ Source or Header  |  1993-09-10  |  2KB  |  58 lines

  1. /*
  2.  * Copyright (C) 1992 by Rush Record (rhr@clio.rice.edu)
  3.  * 
  4.  * This file is part of ED.
  5.  * 
  6.  * ED is free software; you can redistribute it and/or modify it under the terms
  7.  * of the GNU General Public License as published by the Free Software Foundation.
  8.  * 
  9.  * ED is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
  10.  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
  11.  * PARTICULAR PURPOSE.  See the GNU General Public License for more details.
  12.  * 
  13.  * You should have received a copy of the GNU General Public License along with ED
  14.  * (see the file COPYING).  If not, write to the Free Software Foundation, 675
  15.  * Mass Ave, Cambridge, MA 02139, USA.
  16.  */
  17. #include "opsys.h"
  18.  
  19. #include <stdio.h> 
  20. #include <stdlib.h> 
  21. #include <string.h> 
  22.  
  23. #include "memory.h"
  24. #include "rec.h"
  25. #include "buffer.h"
  26.  
  27. /******************************************************************************\
  28. |Routine: buffer_append
  29. |Callby: command copier killer output_file
  30. |Purpose: Appends a record or a portion of a record to an existing buffer.
  31. |Arguments:
  32. |    buf is the existing buffer.
  33. |    rec is the record containing the data to be appended.
  34. |    byt1,byt2 define the portion of the record that is to be appended.
  35. \******************************************************************************/
  36. void buffer_append(buf,rec,byt1,byt2)
  37. register buf_ptr buf;
  38. register rec_ptr rec;
  39. register Int byt1,byt2;
  40. {
  41.     rec_ptr new;
  42.     Int l;
  43.  
  44.     new = (rec_ptr)imalloc(sizeof(rec_node));
  45.     if((l = byt2 - byt1) > 0)
  46.     {
  47.         new->data = (Char *)imalloc(l + 1);
  48.         memcpy(new->data,rec->data + byt1,l);
  49.         new->data[l] = '\0';
  50.         new->recflags = 1;    /* it is a freeable buffer */
  51.     }
  52.     else
  53.         new->data = NULL;
  54.     new->length = l;
  55.     insq(new,buf->last);
  56. }
  57.  
  58.